package com.agritech.mapper;

import com.agritech.entity.Question;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 问题Mapper接口
 */
@Mapper
public interface QuestionMapper {
    
    /**
     * 根据用户ID查询问题列表
     * @param userID 用户ID
     * @return 问题列表
     */
    @Select( "SELECT id,user_id as userID, question_text as questionText , create_time as createTime ,category_name as categoryName   FROM question WHERE user_id = #{userID}")
    List<Question> selectByUserId(Long userID);
    
    /**
     * 根据ID查询问题
     * @param id 问题ID
     * @return 问题对象
     */
    @Select( "SELECT id,user_id as userID, question_text as questionText , create_time as createTime ,category_name as categoryName FROM question WHERE id = #{id}")
    Question selectById(Long id);
    
    /**
     * 查询所有问题
     * @return 问题列表
     */


    @Select( "SELECT id,user_id as userID, question_text as questionText , create_time as createTime ,category_name as categoryName FROM question")
    List<Question> selectAll();
    
    /**
     * 插入新问题
     * @param question 问题对象
     * @return 影响行数
     */
    //@Select( "INSERT INTO question (user_id, question_text, create_time, status) VALUES (#{userId}, #{questionText}, #{createTime}, #{status})")
    @Insert( "INSERT INTO question (user_id, question_text, create_time,category_name) VALUES (#{userID}, #{questionText}, #{createTime},#{categoryName})")
    int insert(Question question);
    
    /**
     * 更新问题状态
     * @param question 问题对象
     * @return 影响行数
     */
    @Select( "UPDATE question SET status = #{status} WHERE id = #{id}")
    int updateStatus(Question question);

    /**
     * 根据id删除操作
     * @param id
     * @return
     */
    @Delete( "DELETE FROM question WHERE id = #{id}")
    int deleteById(Long id);

}    